<template>
	<xh-list-container
		ref="pageList"
		title="吊瓶检验"
		:request="request"
		@clickAdd="handleClickAdd"
		:columns="columns"
		rowKey="id"
	>
		<template v-slot="scope">
			<xh-list-item
				v-for="(item, index) in scope.data"
				:item-data="item"
				:index="index"
				:key="item.id"
				:columns="columns"
				@click="handleClickDetail(item)"
				@clickBtns="handleClickBtns"
				:buttons="[
					{
						text: '编辑',
						key: 'edit',
						color: 'primary',
					},
					{
						text: '删除',
						key: 'delete',
						color: 'error',
					},
				]"
			/>
		</template>
	</xh-list-container>
</template>

<script>
import { getBottleList, deleteBottle } from '@/api/purchase/bottleInspect.js';
import { BottleTypeEnum } from '@/utils/constant';
export default {
	name: 'bottleInspect',
	data() {
		return {
			request: getBottleList,
			columns: [
				{
					label: '产品名称',
					key: 'productName',
					search: false,
				},
				{
					label: '数量',
					key: 'quantity',
					search: false,
				},
				{
					label: '编号',
					key: 'code',
					search: true,
					searchOrder: 3,
				},
				{
					label: '类型',
					key: 'type',
					valueMapList: BottleTypeEnum,
					searchOrder: 2,
				},
				{
					label: '检验时间',
					key: 'inspectDate',
					searchType: 'daterange',
					searchOrder: 1,
				},
				{
					label: '结论',
					key: 'conclusionName',
					search: false,
				},
			],
		};
	},
	onShow() {
		this.$refs.pageList?._query();
	},
	methods: {
		handleClickDetail() {},
		handleClickBtns(btnKey, item, index) {
			if (btnKey === 'delete') {
				this.handleDeleteItem(item, index);
			} else if (btnKey === 'edit') {
				this.$nav.navigateTo('/subPurchaseManage/bottleInspect/editForm', item);
			}
		},
		handleClickAdd() {
			this.$nav.navigateTo('/subPurchaseManage/bottleInspect/addForm');
		},
		handleDeleteItem(item) {
			const { id, type } = item;
			this.$modal.confirm('确定删除吗？').then(() => {
				deleteBottle({ id, type }).then(() => {
					this.$modal.msgSuccess('删除成功！');
					this.$refs.pageList?._query();
				});
			});
		},
	},
};
</script>
